package com.web.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.web.enums.StateEnum;
import com.web.validator.PhoneValidator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.*;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.util.Date;

@ApiModel("用户对象")
//@ApiModel(value = "用户对象",description = "用户对象描述")
//@NoArgsConstructor //生成一个无参数的构造方法
//@AllArgsConstructor  //生成一个包含所有变量

@Data
@TableName("user")
public class User implements Serializable {

    public interface UpdateGroup extends Default{
    }

    public interface InsertGroup extends Default {
    }

//    @TableId(type = IdType.ASSIGN_ID)
    @TableId(type = IdType.AUTO,value = "id")
    @Null(message = "id必须为空")
    private Long id;

    @PhoneValidator.phone
    @NotNull(message = "username cannot be null",groups = InsertGroup.class)
    @NotEmpty(message = "姓名不能为空",groups = InsertGroup.class)
    @NotEmpty(message = "姓名不能为空",groups = UpdateGroup.class)
    @ApiModelProperty(required = true,value = "用户名", example = "张三")
    @TableField(value = "name")
    private String name;

    @Min(value = 1 , message = "年龄不能小于1岁")
    @Max(value = 100 , message = "年龄不能大于100岁")
    @ApiModelProperty("年龄")
    private Integer age;

    @Email
    private String email;

    @ApiModelProperty(value = "状态：1=启用；0=禁用", allowableValues = "0,1", example = "1")
    private StateEnum state;
    //private Integer state;

    @TableField(exist = false)
    private String stateDescp;

    @TableLogic
    private Integer deleted;

    @TableField(fill = FieldFill.INSERT)
    private Date createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    public void  setStateDescp(StateEnum state){
        this.stateDescp = StateEnum.getByDescp(state.getCode());
    }

    public String getStateDescp(){
        return stateDescp;
    }

    @TableField(exist = false)
    private UserInfo userInfo;
//    private List<Blog> blogs; utf8mb4_general_ci

}
